package com.easemob.helpdesk.adapter;

import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.easemob.helpdesk.bean.ServiceFeeBean;
import com.housekeeperapp.R;
import com.reactnativenavigation.layouts.Layout;

import java.util.List;


/**
 * Created by xiaolong.wei on 2018/12/18.
 */

public class ServiceFeeAdapter extends BaseAdapter {
    List<ServiceFeeBean> mDatas;
    Context mContext;
    LayoutInflater mInflater;

    public ServiceFeeAdapter(List<ServiceFeeBean> mDatas, Context mContext) {
        this.mDatas = mDatas;
        this.mContext = mContext;
        mInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ServiceFeeBean serviceFeeBean = mDatas.get(position);
        Holder holder = null;
        if (convertView == null){
            convertView = mInflater.inflate(R.layout.service_fee_list_item,parent,false);
            holder = new Holder(convertView);
            convertView.setTag(holder);
        }
        holder = (Holder) convertView.getTag();

        if (serviceFeeBean != null){
            if ("buy".equals(serviceFeeBean.getService_type())){
                holder.type.setText("代买");
            }else if ("send".equals(serviceFeeBean.getService_type())){
                holder.type.setText("代送");
            }else if ("express".equals(serviceFeeBean.getService_type())){
                holder.type.setText("快递");
            }else if ("lockkey".equals(serviceFeeBean.getService_type())){
                holder.type.setText("钥匙保管");
            }else if ("other".equals(serviceFeeBean.getService_type())){
                if ("appointment".equals(serviceFeeBean.getOtherServiceType())){
                    holder.type.setText("预约办理");
                }else if ("report".equals(serviceFeeBean.getOtherServiceType())){
                    holder.type.setText("报事");
                }else if ("repair".equals(serviceFeeBean.getOtherServiceType())){
                    holder.type.setText("报修");
                }else if ("activity".equals(serviceFeeBean.getOtherServiceType())){
                    holder.type.setText("活动报名");
                }else if ("other".equals(serviceFeeBean.getOtherServiceType())){
                    holder.type.setText("其他");
                }
            }else if ("nursing".equals(serviceFeeBean.getService_type())){
                holder.type.setText("护理服务");
            }
            holder.fee.setText(Html.fromHtml("每单加<font color='#EA5404'>"+serviceFeeBean.getFee().setScale(2).toString()+"</font>元"));
        }
        return convertView;
    }

    static class Holder{

        TextView type;
        TextView fee;

        public Holder(View view) {
            type=view.findViewById(R.id.type);

            fee=view.findViewById(R.id.fee);
        }
    }
}
